package com.itheima.health.service.impl;

import com.itheima.health.dao.MemberDao;
import com.itheima.health.dao.OrderDao;
import com.itheima.health.pojo.Order;
import com.itheima.health.service.ReportService;
import com.itheima.health.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class ReportServiceImpl implements ReportService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private MemberDao memberDao;
    @Override
    public Map<String, Object> getBusinessReportData() {
        Map<String,Object> map = new HashMap<>();
        //时间转成字符串 Date >  String
        //日期
        String today = DateUtils.getDateFormat(new Date());
        //获取本周一日期
        String lastWeek = DateUtils.getDateFormat(DateUtils.getFirstDayOfWeek());
        //获取本月一号
        String month = DateUtils.getDateFormat(DateUtils.getFirstDayOfMonth());
        //获取今日新增会员
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //返回会员总数
        Integer totalMember = memberDao.findMemberCount();
        //返回本周新增会员
        Integer thisWeekNewMember = memberDao.findMemberCountWeekByDate(lastWeek);
        //返回本月新增会员
        Integer thisMonthNewMember = memberDao.findMemberCountMonthByDate(month);
        //返回本日预约人数
        Integer todayOrderNumber = orderDao.findMemberCountByDate(today);
        //返回本周预约人数
        Integer thisWeekOrderNumber = orderDao.findMemberCountWeekByDate(lastWeek);
        //返回本月预约人数
        Integer thisMonthOrderNumber = orderDao.findMemberCountMonthByDate(month);
        //本日到诊数
        Integer todayVisitsNumber = orderDao.findVisitCountByDate(today);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitCountWeekByDate(lastWeek);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitCountMonthByDate(month);
        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        map.put("hotSetmeal",hotSetmeal);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("totalMember",totalMember);
        map.put("reportDate", today);
        map.put("todayNewMember",todayNewMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        return map;
    }
}
